Previous Book Contents Book Index Next

Inside Macintosh: Programming With JManager /
Chapter 1 - Using JManager


Instantiating Applets

After you have created a session, located the applet, and created an AWT context for the applet, you can instantiate it. An instantiated applet is defined by an JMAppletViewerRef object, and you use the JMNewAppletViewer function (page 77) to create one. Listing 1-10 shows an example of instantiating an applet.

Listing 1-10 Instantiating an applet

JMAppletViewerCallbacks viewerCallbacks = {
   kJMVersion,        /* should be kJMVersion */
   MyShowDocument,    /* showDocument callback */
   MySetStatusMsg     /* setMessage callback */
   };

JMAppletViewerRef viewer;
err = JMNewAppletViewer(&viewer, context, locatorRef, 
      appletIndex, &viewerCallbacks, 0);

/* reload the applet to get it going */
if (err == noErr) {
    err = JMReloadApplet(viewer);
You must define two callbacks, MyShowDocument (page 107) and MySetStatusMsg (page 107), when calling the JMNewAppletViewer function. The MyShowDocument function displays the contents of a URL passed back from the applet, and MySetStatusMsg displays any status messages the applet may pass to the application. You must also specify the index of the applet you want to instantiate (as returned by JMCountApplets).

After you have instantiated the applet viewer object, you must load and execute the applet code by calling the function JMReloadApplet (page 79).

You can set or retrieve client data associated with the applet by using the functions JMSetAppletViewerData (page 79) and JMGetAppletViewerData (page 78).

At any time you can stop execution of the applet by calling the JMSuspendApplet function (page 80) and resume it by calling the JMResumeApplet function (page 81). If you want to restart the applet without reloading it from the server, use the JMRestartApplet function (page 80).

When you are finished with an applet, you can dispose of it by calling the JMDisposeAppletViewer function (page 78). This function automatically halts applet execution and removes any frames associated with the applet.


Previous Book Contents Book Index Next

© Apple Computer, Inc.
23 APR 1997